package com.ww.editsms.widget.wheel;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.Button;

import com.chinawangw.R;
import com.ww.editsms.widget.wheel.widget.ArrayWheelAdapter;
import com.ww.editsms.widget.wheel.widget.WheelView;


public class WheelTxt {

	private Context context;
	private Dialog dlg;

	private WheelView wheel1;
	private Button sure, cancel;
	private int result;

	public WheelTxt(Context context) {
		this.context = context;
	}

	/**
	 * 公共对话框.
	 * @param title 标题
	 * @param content 内容
	 * @param okClick 确定按钮点击事件.
	 * @return AlertDialog
	 */
	public void show(String[] data1, int check1) {
		dlg = new Dialog(context, R.style.MyDialog);
		dlg.show();
		Window window = dlg.getWindow();
		window.setContentView(R.layout.core_wheel_1);
		findView(window);
		initiWheelView(data1, check1);
		sure.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				result = wheel1.getCurrentItem();
				cancel();// 此处一定要调用finish()方法
			}
		});
		cancel.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				result = -1;
				cancel();// 此处一定要调用finish()方法
			}
		});
	}

	private void findView(Window window) {
		wheel1 = (WheelView) window.findViewById(R.id.wheel1_1);
		sure = (Button) window.findViewById(R.id.buttonsure);
		cancel = (Button) window.findViewById(R.id.buttoncancle);
	}

	public int getResult() {
		return result;
	}

	private void initiWheelView(String[] data1, int check1) {
		wheel1.setVisibleItems(5);
		wheel1.setAdapter(new ArrayWheelAdapter<String>(data1));
		wheel1.setCurrentItem(check1);
	}

	public void cancel() {
		if (dlg != null) {
			dlg.cancel();
		}
	}
}
